package de.hsw.facebook.model.rowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import de.hsw.facbook.model.dao.AccountDAO;
import de.hsw.facbook.model.dao.factory.AccountDAOFactory;
import de.hsw.facbook.model.entities.Message;

public class MessageRowMapper {

	private final Log logger = LogFactory.getLog(MessageRowMapper.class);
	private final AccountDAO accountDAO = AccountDAOFactory.getInstance();

	public Message mapRow(ResultSet rs) throws SQLException {
		
		logger.debug("entering MessageRowMapper");
		Message result = new Message();
		result.setId(rs.getInt("messageID"));
		result.setSender(accountDAO.getByID(rs.getInt("accountID")));
		result.setSubject(rs.getString("subject"));
		result.setText(rs.getString("text"));
		result.setReciever(accountDAO.getByID(rs.getInt("reciever")));

		return result;
	}

}
